home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createRampFromSurface.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.8 KB  |  145 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. includeEffectsGlobals();
  18.  
  19. global proc string createRampFromSurface( string $surface, int $width, int $height, int $hideRamps )
  20. {
  21.     string $surfaceShape = getShapeFromObject( $surface, 0, 0 );
  22.     if( `nodeType $surfaceShape` != "nurbsSurface" )
  23.     {
  24.         return "";
  25.     }
  26.  
  27.     float $minWidth = `getAttr ($surfaceShape+".minValueU")`;
  28.     float $maxWidth = `getAttr ($surfaceShape+".maxValueU")`;
  29.     float $minHeight = `getAttr ($surfaceShape+".minValueV")`;
  30.     float $maxHeight = `getAttr ($surfaceShape+".maxValueV")`;
  31.  
  32.     $width = max( 2, $width );
  33.     float $rangeU = $maxWidth - $minWidth;
  34.     float $stepU = 1.0 / ( $width - 1.0 );
  35.  
  36.     $height = max( 2, $height );
  37.     float $rangeV = $maxHeight - $minHeight;
  38.     float $stepV = 1.0 / ( $height - 1.0 );
  39.  
  40.     string $ramps[];
  41.     clear( $ramps );
  42.  
  43.     string $ramp;
  44.     //
  45.     // If we were told to hide the generated ramps, then we
  46.     // just create them with the "createNode" command.  This
  47.     // does not register them as shading nodes so they will not
  48.     // show up in "Textures" tab of the Visor, HyperShade, and
  49.     // MultiLister.  They can easily clutter the UI with unneeded
  50.     // ramp textures.
  51.     //
  52.     // If we do not want to hide the rams, then we use the
  53.     // "shadingNode" command to create the ramps.  This creates
  54.     // them and registers them as shading nodes to be displayed
  55.     // in the UI.
  56.     //
  57.     // Regardless of the hiding option, they will show up in both
  58.     // the HyperGraph and HyperShade's network representations.
  59.     //
  60.     if( $hideRamps == 1 )
  61.     {
  62.         createNode ramp;
  63.         $ramp = getSelectedObject( 0 );
  64.     }
  65.     else
  66.     {
  67.         $ramp = `shadingNode -asTexture ramp`;
  68.     }
  69.     select $ramp;
  70.     rename $ramp ("SurfaceRamp#");
  71.     $ramp = getSelectedObject( 0 );
  72.     $ramps = appendSingleToStringArray( $ramps, $ramp );
  73.     setAttr ($ramp+".type") 1;
  74.     setAttr ($ramp+".interpolation") 4;
  75.  
  76.     createNode plusMinusAverage;
  77.     rename "SurfaceRampCenter#";
  78.     string $centerPMA = getSelectedObject( 0 );
  79.     setAttr ($centerPMA+".operation") 3;
  80.  
  81.     addAttr -at message -ln "rampCenter" $ramp;
  82.     connectAttr ($centerPMA+".message") ($ramp+".rampCenter");
  83.  
  84.     //
  85.     // This polygonal plane will give an exact representation of the
  86.     // points on the surface that are being sampled to generate the
  87.     // ramps.  Its vertices will be driven directly by the pointOnSurfaceInfo
  88.     // nodes that sample the surface.
  89.     //
  90.     polyPlane -w 0.00001 -h 0.00001 -sx ($width-1) -sy ($height-1) -ch 0;
  91.     rename "rampResolutionPlane#";
  92.     string $polyPlane = getSelectedObject( 0 );
  93.  
  94.     int $u, $v;
  95.     for( $u = 0; $u < $width; $u ++ )
  96.     {
  97.         float $ratioU = $u / ($width - 1.0);
  98.         setAttr ($ramp+".colorEntryList["+$u+"].position") $ratioU;
  99.         string $rampV;
  100.         if( $hideRamps == 1 )
  101.         {
  102.             createNode ramp;
  103.             $rampV = getSelectedObject( 0 );
  104.         }
  105.         else
  106.         {
  107.             $rampV = `shadingNode -asTexture ramp`;
  108.         }
  109.         select $rampV;
  110.         rename $rampV ("SubSurfaceRamp#");
  111.         $rampV = getSelectedObject( 0 );
  112.         setAttr ($rampV+".interpolation") 4;
  113.         $ramps = appendSingleToStringArray( $ramps, $rampV );
  114.         for( $v = 0; $v < $height; $v ++ )
  115.         {
  116.             int $centerIndex = $u * $height + $v;
  117.             float $ratioV = $v / ($height - 1.0);
  118.             setAttr ($rampV+".colorEntryList["+$v+"].position") $ratioV;
  119.  
  120.             string $posi = `createNode pointOnSurfaceInfo`;
  121.             connectAttr ($surfaceShape+".worldSpace[0]") ($posi+".inputSurface");
  122.             setAttr ($posi+".turnOnPercentage") 1;
  123.             setAttr ($posi+".parameterU") $ratioU;
  124.             setAttr ($posi+".parameterV") $ratioV;
  125.  
  126.             connectAttr ($posi+".result.position") ($rampV+".colorEntryList["+$v+"].color");
  127.             connectAttr ($posi+".result.position") ($centerPMA+".input3D["+$centerIndex+"]");
  128.  
  129.             //
  130.             // Connect this pointOnSurfaceInfo node's resulting position to the
  131.             // corresponding vertex of the resolutionPlane.
  132.             //
  133.             connectAttr ($posi+".result.position") ($polyPlane+".vtx["+($v*$width+$u)+"]");
  134.         }
  135.         connectAttr ($rampV+".outColor") ($ramp+".colorEntryList["+$u+"].color");
  136.     }
  137.  
  138.     // select $ramps;
  139.     // sets -name "RampFromSurfaceSet#";
  140.  
  141.     select $ramp $polyPlane;
  142.     return $ramp;
  143. }
  144.  
  145.